<?php

namespace App\Http\Controllers\Admin;

use App\Http\Response;
use App\News;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class NewsController extends Controller
{
    use Response;


    public function index(Request $request)
    {
        $result=News::latest()->paginate($request->get('pageSize'),'*','pageNo');
        return $this->success(200,$result);
    }

    public function store(Request $request)
    {
        News::create($request->all());
        return $this->message(200,'创建成功');
    }
    public function show($id,Request $request)
    {
        $list=News::where('id',$id)->first();

        return $this->success(200,$list);
    }
    public function update($id,Request $request)
    {
       $update=News::where('id',$id)->update($request->all());
        if ($update){
            return $this->message(200,'更新成功');
        }else{
            return $this->error(505,'更新失败');
        }
    }
    public function destroy($id)
    {
        $delete=News::destroy($id);
        if ($delete){
            return $this->message(200,'删除成功');
        }else{
            return $this->error(505,'删除失败');
        }
    }
}
